package com.quectel.grid.controller.village;


import cn.hutool.core.lang.func.LambdaUtil;
import com.quectel.core.module.village.dto.VillageRoomDto;
import com.quectel.core.module.village.service.VillageRoomService;
import com.quectel.grid.controller.BaseController;
import com.quectel.util.common.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 在这里编写说明
 *
 * @author: bob
 * @email: bob.yu@quectel.com
 * @date: 2023-02-16 09:48:00
 */
@RestController
@RequestMapping("villageRoom")
@Tag(name = "VillageRoomController", description = "房间相关api")
public class VillageRoomController extends BaseController {

    @DubboReference
    private VillageRoomService villageRoomService;

    @GetMapping("queryByBuildingId")
    @Operation(summary = "通过单元id查询房屋信息")
    public Response<List<VillageRoomDto>> queryByBuildingId(
            @Parameter(description = "楼层") @RequestParam Long buildingId) {
        Map<String, Object> sqlMap = new HashMap<>();
        sqlMap.put(LambdaUtil.getFieldName(VillageRoomDto::getBuildingId), buildingId);
        return Response.<List<VillageRoomDto>>ok().wrap(villageRoomService.queryList(sqlMap));
    }


    @GetMapping("queryByFloorId")
    @Operation(summary = "楼层筛选房屋")
    public Response<List<VillageRoomDto>> queryByFloorId(
            @Parameter(description = "楼层") @RequestParam Long floorId
    ) {

        return Response.<List<VillageRoomDto>>ok().wrap(villageRoomService.selectByFloorId(floorId));
    }
}
